package day04;

import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String s = input.nextLine();
        System.out.println(reverseWords(s));
    }

    /**
     * 给定一个字符串 s ，你需要反转字符串中每个单词的字符顺序，同时仍保留空格和单词的初始顺序。
     *
     * @param s
     * @return
     */
    public static String reverseWords(String s) {
        //全局变量
        int i = 0, j = 0;
        char result[] = s.toCharArray();
        for (; j < s.length(); j++) {
            if (result[j] == ' ') {
                reversed(result, i, j - 1);
                i = j + 1;
                j = i;
            }
        }
        reversed(result, i, result.length - 1);
/*        String answer = new String(result);
        return answer;*/
        s = String.valueOf(result);
        return s;
    }

    public static void reversed(char[] chars, int left, int right) {
        while (left < right) {
            char temp = chars[left];
            chars[left] = chars[right];
            chars[right] = temp;
            left++;
            right--;
        }
    }
}
